<?php

class RBAC {

    public function init() {
        $auth = Yii::app()->authManager;

        $auth->createOperation('viewDashboard', 'create a post');
        $auth->createOperation('readPost', 'read a post');
        $auth->createOperation('updatePost', 'update a post');
        $auth->createOperation('deletePost', 'delete a post');

       // $bizRule = 'return Yii::app()->user->id==$params["post"]->authID;';
        $task = $auth->createTask('administration', 'Using administration panel');
        $task->addChild('updatePost');

        $role = $auth->createRole('reader');
        $role->addChild('readPost');

        $role = $auth->createRole('author');
        $role->addChild('reader');
        $role->addChild('createPost');
        $role->addChild('updateOwnPost');

        $role = $auth->createRole('editor');
        $role->addChild('reader');
        $role->addChild('updatePost');

        $role = $auth->createRole('admin');
        $role->addChild('editor');
        $role->addChild('author');
        $role->addChild('deletePost');

        $auth->assign('reader', 'readerA');
        $auth->assign('author', 'authorB');
        $auth->assign('editor', 'editorC');
        $auth->assign('admin', 'adminD');
    }

}

?>
